/*
 *
 *  Copyright (C) 2010 Tal Eisenberg
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package tal.drivechain.module.properties;

import java.util.HashMap;
import org.w3c.dom.NodeList;

/**
 * 
 * @author Main
 */
public class PropertyParserFactory {
    private enum Parser {
        VAR_PARSER ("var-parser") 
            { public PropertyParser getPropertyParser() { return new VarParser(); } },
        TRIGGER_PARSER ("trigger-parser")
            { public PropertyParser getPropertyParser() { return new TriggerParser(); } },
        WILDCARD_PARSER ("wildcard-parser")
            { public PropertyParser getPropertyParser() { return new WildcardParser(); } },
        STRING_PARSER ("string-parser")
                    { public PropertyParser getPropertyParser() { return new StringParser(); } },
        RANGE_PARSER ("range-parser")
                    { public PropertyParser getPropertyParser() { return new RangeParser(); } },
        EXPRESSION_PARSER ("expression-parser")
                    { public PropertyParser getPropertyParser() { return new ExpressionParser(); } },
        KEYVALUE_PARSER ("keyvalue-parser") 
                    { public KeyValueParser getPropertyParser() { return new KeyValueParser(); } },
        CUSTOM_PARSER ("custom-parser")
                    { public CustomParser getPropertyParser() { return new CustomParser(); } },
        COMPLEX_PARSER ("complex-parser")
                    { public ComplexParser getPropertyParser() { return new ComplexParser(); } },
        FONT_PARSER ("font-parser")
                    { public FontParser getPropertyParser() { return new FontParser(); } },
        COLOR_PARSER ("color-parser")
                    { public ColorParser getPropertyParser() { return new ColorParser(); } },
        DATE_PARSER ("date-parser")
                    { public DateParser getPropertyParser() { return new DateParser(); } },
        MODULE_PARSER ("module-parser")
                    { public ModuleParser getPropertyParser() { return new ModuleParser(); } },
        KEYCODE_PARSER ("keystroke-parser")
                    { public KeyStrokeParser getPropertyParser() { return new KeyStrokeParser(); } },
        FILE_PARSER ("file-parser")
                    { public FileParser getPropertyParser() { return new FileParser(); } };

        Parser (String name) { this.name = name; }
        
        private final String name;
        public String getName() { return name; }
        public abstract PropertyParser getPropertyParser();
    }
    
    public static PropertyParser createParser(String parserName, HashMap<String, String> parserAttributes, NodeList childElements) {
        for (Parser parser : Parser.values()) {
            if (parser.getName().equals(parserName)) {
                PropertyParser retParser = parser.getPropertyParser();
                retParser.setAttribures(parserAttributes, childElements);
                return retParser;
            }
        }
        throw new IllegalArgumentException("Unknown parser name: " + parserName);
    }

}
